﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

// <summary>
/// Author: IDEALAB
/// Created Date:14-Feb-2011
/// Description:Used to save the Common variables and functions.
/// </summary>
namespace EncircleFTM
{
    public partial class frmViewErrorLog : Form
    {
        /// <summary>
        /// Default constructor
        /// </summary>
        public frmViewErrorLog()
        {
            InitializeComponent();
        }

        /// <summary>
        /// To Load the content of the Error File in the form.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmViewErrorLog_Load(object sender, EventArgs e)
        {
            string ErrorLogContent=string.Empty;
            try
            {
                ErrorLogContent = clsCommonData.ReadLog();
                if (ErrorLogContent == string.Empty)
                    txtErrorLog.Text = clsCommonData.MSG_ERRORLOG;
                else
                    txtErrorLog.Text = ErrorLogContent;
            }
            catch (Exception ex)
            {
                clsCommonData.WriteError(ex.ToString());
            }
        }

        /// <summary>
        /// To Delete the existing Error file and create a new error file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnClearLog_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult result = MessageBox.Show(clsCommonData.MSG_CONFIRM, clsCommonData.STR_APPNAME, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.OK)
                {
                    if (File.Exists(System.IO.Path.Combine(clsCommonData.APP_DATA_PATH, clsCommonData.STR_ERROR_TXT)))
                    {
                        File.Delete(System.IO.Path.Combine(clsCommonData.APP_DATA_PATH, clsCommonData.STR_ERROR_TXT));
                        StreamWriter writer = new StreamWriter(System.IO.Path.Combine(clsCommonData.APP_DATA_PATH, clsCommonData.STR_ERROR_TXT));
                        writer.WriteLine("-----------");
                        writer.Close();
                        writer = null;
                        txtErrorLog.Text = string.Empty;
                        clsSettings.UpdateClearLogDate(DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year,
                    DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
                    }
                    else
                    {
                        File.Create(System.IO.Path.Combine(clsCommonData.APP_DATA_PATH, clsCommonData.STR_ERROR_TXT));
                    }
                }
            }
            catch (Exception ex)
            {
                clsCommonData.WriteError(ex.Message);
            }
        }

        /// <summary>
        /// Used to close the screen
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
